home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / alv.sun / alv.lha / src / rasregion.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  1.6 KB  |  74 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3.  
  4. har           *progname;
  5. har           *filename;
  6. ixrect        *pr1, *pr2;
  7.  
  8. #ifdef STANDALONE
  9. ain(argc, argv, envp)
  10. #else
  11. asregion_main(argc, argv, envp)
  12. #endif
  13.     int             argc;
  14.     char          **argv;
  15.     char          **envp;
  16. {
  17.     register int    i, j;
  18.     int             levels;
  19.     int             xoffset, yoffset, xsize, ysize;
  20.     colormap_t        colormap;
  21.  
  22.     xsize = ysize = 0;
  23.     xoffset = yoffset = -1;
  24.     progname = strsave(argv[0]);
  25.     parse_profile(&argc, argv, envp);
  26.  
  27.     while ((gc = getopt(argc, argv, "x:y:X:Y:")) != EOF)
  28.         switch (gc) {
  29.         case 'x':
  30.             xoffset = atoi(optarg);
  31.             break;
  32.         case 'y':
  33.             yoffset = atoi(optarg);
  34.             break;
  35.         case 'X':
  36.             xsize = atoi(optarg);
  37.             break;
  38.         case 'Y':
  39.             ysize = atoi(optarg);
  40.             break;
  41.         case '?':
  42.             errflag++;
  43.             break;
  44.         }
  45.  
  46.     if (errflag)
  47.         error((char *) 0, "Usage: %s: [-x xoffset] [-y yoffset] [-X xsize] [-Y ysize] [infile] [outfile]\n", progname);
  48.  
  49.     for (stream = 0; optind < argc; stream++, optind++)
  50.         if (stream < 2 && strcmp(argv[optind], "-") != 0)
  51.             if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
  52.                 error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
  53.  
  54.     if ((pr1 = pr_load(stdin, &colormap)) == NULL)
  55.         error(PR_IO_ERR_RASREAD);
  56.  
  57.     if (xsize == 0)
  58.         xsize = pr1->pr_size.x / 2;
  59.  
  60.     if (ysize == 0)
  61.         ysize = pr1->pr_size.y / 2;
  62.  
  63.     if (xoffset == -1)
  64.         xoffset = pr1->pr_size.x / 4;
  65.  
  66.     if (yoffset == -1)
  67.         yoffset = pr1->pr_size.y / 4;
  68.  
  69.     if ((pr2 = pr_region(pr1, xoffset, yoffset, xsize, ysize)) == NULL)
  70.         error("pr_region returned NULL");
  71.  
  72.     pr_dump(pr2, stdout, &colormap, RT_STANDARD, 0);
  73. }
  74.